package game

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/model/game"
	gameReq "github.com/flipped-aurora/gin-vue-admin/server/model/game/request"
	"github.com/flipped-aurora/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type GameZoneApi struct{}

var gameZoneService = service.ServiceGroupApp.GameServiceGroup.GameZoneService

// CreateGameZone 创建gameZone表
// @Tags GameZone
// @Summary 创建gameZone表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body game.GameZone true "创建gameZone表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /gameZone/createGameZone [post]
func (gameZoneApi *GameZoneApi) CreateGameZone(c *gin.Context) {
	var gameZone game.GameZone
	err := c.ShouldBindJSON(&gameZone)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	if err := gameZoneService.CreateGameZone(&gameZone); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteGameZone 删除gameZone表
// @Tags GameZone
// @Summary 删除gameZone表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body game.GameZone true "删除gameZone表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /gameZone/deleteGameZone [delete]
func (gameZoneApi *GameZoneApi) DeleteGameZone(c *gin.Context) {
	ID := c.Query("ID")
	if err := gameZoneService.DeleteGameZone(ID); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteGameZoneByIds 批量删除gameZone表
// @Tags GameZone
// @Summary 批量删除gameZone表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /gameZone/deleteGameZoneByIds [delete]
func (gameZoneApi *GameZoneApi) DeleteGameZoneByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	if err := gameZoneService.DeleteGameZoneByIds(IDs); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateGameZone 更新gameZone表
// @Tags GameZone
// @Summary 更新gameZone表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body game.GameZone true "更新gameZone表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /gameZone/updateGameZone [put]
func (gameZoneApi *GameZoneApi) UpdateGameZone(c *gin.Context) {
	var gameZone game.GameZone
	err := c.ShouldBindJSON(&gameZone)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	if err := gameZoneService.UpdateGameZone(gameZone); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindGameZone 用id查询gameZone表
// @Tags GameZone
// @Summary 用id查询gameZone表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query game.GameZone true "用id查询gameZone表"
// @Success 200 {object} response.Response{data=object{regameZone=game.GameZone},msg=string} "查询成功"
// @Router /gameZone/findGameZone [get]
func (gameZoneApi *GameZoneApi) FindGameZone(c *gin.Context) {
	ID := c.Query("ID")
	if regameZone, err := gameZoneService.GetGameZone(ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(regameZone, c)
	}
}

// GetGameZoneList 分页获取gameZone表列表
// @Tags GameZone
// @Summary 分页获取gameZone表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query gameReq.GameZoneSearch true "分页获取gameZone表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /gameZone/getGameZoneList [get]
func (gameZoneApi *GameZoneApi) GetGameZoneList(c *gin.Context) {
	var pageInfo gameReq.GameZoneSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := gameZoneService.GetGameZoneInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetGameZoneAll 获取gameZone表列表
// @Tags GameZone
// @Summary 分页获取gameZone表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=[]game.GameZone,msg=string} "获取成功"
// @Router /gameZone/getGameZoneAll [get]
func (gameZoneApi *GameZoneApi) GetGameZoneAll(c *gin.Context) {
	if list, err := gameZoneService.GetGameZoneInfoAll(); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(list, "获取成功", c)
	}
}

// GetGameZonePublic 不需要鉴权的gameZone表接口
// @Tags GameZone
// @Summary 不需要鉴权的gameZone表接口
// @accept application/json
// @Produce application/json
// @Param data query gameReq.GameZoneSearch true "分页获取gameZone表列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /gameZone/getGameZonePublic [get]
func (gameZoneApi *GameZoneApi) GetGameZonePublic(c *gin.Context) {
	// 此接口不需要鉴权
	// 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
	response.OkWithDetailed(gin.H{
		"info": "不需要鉴权的gameZone表接口信息",
	}, "获取成功", c)
}
